/**
 * js入口
 */

//js路径
var JS_PATH = "./";
Ext.application({
    name: "app",
    appFolder: "js/app",//js加载路径
    autoCreateViewport: true,
    //控制器
    controllers: ["demo.UserController"],
    launch: function () {
        //1.加载系统配置信息
        Ext.Ajax.request({
            url: JS_PATH + "js/app/data/session.json",
            success: function (response, opts) {
                var obj = Ext.decode(response.responseText);
                var footer = Ext.getCmp("footer");
                footer.add("当前用户：" + obj.userInfo.userName);
                footer.add("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                footer.add("-");
                footer.add("版本：" + obj.sysInfo.version);
                footer.add(Ext.create("Ext.toolbar.Fill"));
                footer.add("技术支持:<a href='" + obj.sysInfo.url + "' target='_blank' style='text-decoration:none;'>" +
                    "<font color='#0000FF'>" + obj.sysInfo.url + "</font></a>&nbsp;&nbsp;");
            },
            failure: function (response, opts) {
                console.log("server-side failure with status code " + response.status);
            }
        });

        //2.加载菜单
        var menu = Ext.getCmp("menuPanel");
        if (menu) {
            var store = Ext.create("app.store.demo.Menus");
            var tree = Ext.create('Ext.tree.Panel', {
                border:false,
                store: store,
                rootVisible: false,//隐藏根节点
                listeners: {
                    itemclick: function (obj, record, item, index, e, eOpts) {
                        if (record.data.leaf) {
                            var tabs = Ext.getCmp("tabs");
                            if (record.data.url) {
                                var newTab = Ext.create(record.data.url);
                                if (!tabs.contains(newTab)) {
                                    tabs.add(newTab);
                                }
                                tabs.setActiveTab(newTab);
                            }
                        }
                    }
                },
            });
            menu.add(tree);
        }
    }
});
